package com.stu.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.stu.model.Admin;

/**
 * @author Fairy
 */
public class AdminDao extends BaseDao {
	/**
	 ** 管理员登陆
	 */
	public Admin login(Admin admin) {
		String sql = "select * from s_admin where name=? and password=?";
		Admin adminRst = null;
		try {
			PreparedStatement preparedStatement = con.prepareStatement(sql);
			preparedStatement.setString(1, admin.getName());
			preparedStatement.setString(2, admin.getPassword());
			ResultSet resultSet = preparedStatement.executeQuery();
			if (resultSet.next()) {
				adminRst = new Admin();
				adminRst.setId(resultSet.getInt("id"));
				adminRst.setName(resultSet.getString("name"));
				adminRst.setPassword(resultSet.getString("password"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return adminRst;
	}
}
